/* xbdhtml.js (Cross-Browser Nav4/IE4 DHTML API) 
   14 May 98, Eric Krock, Copyright Netscape Communications
   Permission is granted to reuse, redistribute, and modify 
   without charge. 

   THIS IS THE COMPRESSED, COMMENT-FREE VERSION OF xbdhtml.js.
   For commented version, see 
   http://developer.netscape.com/docs/technote/dynhtml/csspapi/xbdhtml.js
*/

function Is ()
{   // convert all characters to lowercase to simplify testing
    var agt=navigator.userAgent.toLowerCase()

    // --- BROWSER VERSION ---
    this.major = parseInt(navigator.appVersion)
    this.minor = parseFloat(navigator.appVersion)

    this.nav  = ((agt.indexOf('mozilla')!=-1) && ((agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1)))
    this.nav2 = (this.nav && (this.major == 2))
    this.nav3 = (this.nav && (this.major == 3))
    this.nav4 = (this.nav && (this.major == 4))

    this.ie   = (agt.indexOf("msie") != -1)
    this.ie3  = (this.ie && (this.major == 2))
    this.ie4  = (this.ie && (this.major == 4))

    this.opera = (agt.indexOf("opera") != -1)

    this.nav4up = this.nav && (this.major >= 4)
    this.ie4up  = this.ie  && (this.major >= 4)
}

var is = new Is();

function dw(str, minVersion, maxVersion)
{   if ( ((dw.arguments.length < 3) || (is.major <= maxVersion)) 
         && ((dw.arguments.length < 2) || (is.major >= minVersion)))
    document.write(str)  
}

function dwb (str, aBoolean)
{   if  ((dwb.arguments.length < 2) || aBoolean)
    document.write(str)  
}

function sv(str, minVersion, maxVersion)
{   if ( ((sv.arguments.length < 3) || (is.major <= maxVersion)) 
         && ((sv.arguments.length < 2) || (is.major >= minVersion)))
    return str;
    else return "";
}

function sb (str, aBoolean)
{   if  ((sb.arguments.length < 2) || aBoolean)
    return str;
    else return "";
}

/* The following stub function API for cross-browser HTML 
   element positioning and visibility (CSSP access) was
   derived from Mike Hall's excellent CBDHTML API, which is
   free for downloading, reuse, and modification, and can
   be found online at:
   http://members.aol.com/MHall75819/dhtml/cbdhtml.html
   Thanks also to Danny Goodman (http://www.dannyg.com/)
   and Dan Steinman (http://members.xoom.com/dynduo/).
*/
function layerClipOrder (cssClipString)
{  var commaPos = cssClipString.lastIndexOf(",");
   return (cssClipString.substring(commaPos+1) + "," + cssClipString.substring(0,commaPos));
}

function genElt (name, content, left, top, z, width, height, visibility, 
                 backgroundColor, backgroundImage, clip, relative, 
                 hideEltOnOlderBrowsers, useDivInsteadOfLayer, classname) 
{ var markup = "";
  if (is.nav && (is.major>=4 || !hideEltOnOlderBrowsers) && 
      !useDivInsteadOfLayer)
  { var tagname = (relative)?'ILAYER':'LAYER';
    if (visibility && (visibility!=''))
    {  if (visibility=="hidden") visibility = "hide";
       else if (visibility=="visible") visibility = "show";
    }
    markup = '<' + tagname + ' ID="' + name + '"' + ((classname)?' CLASS="' + 
        classname + '"':'') + ((left)?' LEFT="' + left + '"':'') + 
        ((top)?' TOP="' + top + '"':'') + ((width)?' WIDTH="' + width + '"':'') + 
        ((height)?' HEIGHT="' + height + '"':'') + 
        ((visibility && (visibility!='')) ? ' VISIBILITY="' + visibility + '"' : '') + 
        ((z)?' Z-INDEX="' + z + '"':'') + 
        ((backgroundColor)?' BGCOLOR="' + backgroundColor + '"':'') + 
        ((backgroundImage)?' BACKGROUND="' + backgroundImage + '"':'') +  
        ((clip)?' CLIP="' + layerClipOrder(clip) + '"':'') + 
        '>' + ((content)?content:'') + '</' + tagname + '>';
  }
  else if ((is.ie || (is.nav && useDivInsteadOfLayer)) && (is.major>=4 || !hideEltOnOlderBrowsers))
  { markup = '<DIV ID="' + name + '"' +  
        ((classname)?' CLASS="' + classname + '"':'') + 
        ' STYLE="position:' + ((relative)?'relative;':'absolute;') + 
        ' overflow:none;' + 
        ((left)?' left:' + left + 'px;':'') + 
        ((top)?' top:' + top + 'px;':'') + 
        ((height)?' height:' + height + 'px;':'') + 
        ((width)?' width:' + width + 'px;':'') + 
        ((visibility && (visibility!='')) ? ' visibility:' + visibility + ';' : '') + 
        ((z)?' z-index:' + z + ';':'') + 
        ((backgroundColor)?' background-color:' + backgroundColor + ';':'') + 
        ((backgroundImage)?' background-image:url("' + backgroundImage + '");':'') +  
        ((clip)?' clip:rect("' + clip + '");':'') + 
        '">' + ((content)?content:'') + '</DIV>';
  }
  return markup;
}

function writeElt (name, content, left, top, z, width, height, visibility, 
                   backgroundColor, backgroundImage, clip, relative, 
                   hideEltOnOlderBrowsers, useDivInsteadOfLayer, classname) 
{ if (writeElt.arguments.length < 15) classname = false;
  if (writeElt.arguments.length < 14) useDivInsteadOfLayer = false;
  if (writeElt.arguments.length < 13) hideEltOnOlderBrowsers = false;
  if (writeElt.arguments.length < 12) relative = false;
  if (writeElt.arguments.length < 11) clip = false;
  if (writeElt.arguments.length < 10) backgroundImage = false;
  if (writeElt.arguments.length < 9) backgroundColor = false;
  if (writeElt.arguments.length < 8) visibility = false;
  if (writeElt.arguments.length < 7) height = false;
  if (writeElt.arguments.length < 6) width = false;
  if (writeElt.arguments.length < 5) z = false;
  if (writeElt.arguments.length < 4) top = false;
  if (writeElt.arguments.length < 3) left = false;
  if (writeElt.arguments.length < 2) content = false;
  document.write (genElt (name, content, left, top, z, width, height, visibility, 
                    backgroundColor, backgroundImage, clip, relative, 
                 hideEltOnOlderBrowsers, useDivInsteadOfLayer, classname));
}

function getElt () 
{ if (is.nav4up) {
    var currentLayer = document.layers[getElt.arguments[0]];
    for (var i=1; i<getElt.arguments.length && currentLayer; i++)
    {   currentLayer = currentLayer.document.layers[getElt.arguments[i]];
    }
    return currentLayer;
  } 
  else if (is.ie4up) {
    var elt = eval('document.all.' + getElt.arguments[getElt.arguments.length-1]);
    return(elt);
  }
}

function setEltVisibility (elt, value)
{  if (is.nav4up) elt.visibility = value;
   else if (is.ie4up) elt.style.visibility = value;
}

function getEltVisibility (elt)
{  if (is.nav4up) 
   {  var value = elt.visibility;
      if (value == "show") return "visible";
      else if (value == "hide") return "hidden";
      else return value;
   }
   else if (is.ie4up) return elt.style.visibility;
}

function moveEltTo (elt, x, y) 
{ 
	if ( ! elt ) return ;
	if (is.nav4up) elt.moveTo(x, y);
	else if (is.ie4up) {
		elt.style.pixelLeft = x;
		elt.style.pixelTop  = y;
	}
}

function moveEltBy (elt, x, y) 
{ 
	if ( ! elt ) return ;

if (is.nav4up) elt.moveBy(x, y);
  else if (is.ie4up)  {
    elt.style.pixelLeft += x;
    elt.style.pixelTop  += y;
  }
}

function setEltLeft (elt, x) {
	if ( ! elt ) return ;
  if (is.nav4up)     elt.left=x;
  else if (is.ie4up) elt.style.pixelLeft=x;
}

function getEltLeft (elt) {
	if ( ! elt ) return -1 ;
  if (is.nav4up)     return (elt.left);
  else if (is.ie4up) return (elt.style.pixelLeft);
}

function setEltTop (elt, y) 
{ 
	if ( ! elt ) return  ;
if (is.nav4up)     elt.top=y;
  else if (is.ie4up) elt.style.pixelTop=y;
}

function getEltTop (elt) 
{ 
	if ( ! elt ) return -1 ;
if (is.nav4up)     return (elt.top);
  else if (is.ie4up) return (elt.style.pixelTop);
}

function getEltWidth (elt)
{ 
	if ( ! elt ) return -1;
if (is.nav4up) return(elt.width);
  else if (is.ie4up) return(elt.style.pixelWidth);
}

function getEltHeight (elt)
{ 
	if ( ! elt ) return -1;
	if (is.nav4up) return (elt.height);
  	else if (is.ie4up) return (elt.style.pixelHeight);
}

function setEltClip (elt, cliptop, clipright, clipbottom, clipleft) 
{ 
	if ( ! elt ) return ;
	if (is.nav4up) {
    elt.clip.left   = clipleft;
    elt.clip.top    = cliptop;
    elt.clip.right  = clipright;
    elt.clip.bottom = clipbottom;
  }
  else if (is.ie4up)  elt.style.clip = 'rect(' + cliptop + ' ' +  
       clipright + ' ' + clipbottom + ' ' + clipleft +')';
}

function tempClipObj (elt)
{  var clipStr = elt.style.clip;
   clipStr = clipStr.substring (clipStr.indexOf("(") + 1);
   this.top = parseInt(clipStr);
   clipStr = clipStr.substring (clipStr.indexOf(" ") + 1);
   this.right = parseInt(clipStr);
   clipStr = clipStr.substring (clipStr.indexOf(" ") + 1);
   this.bottom = parseInt(clipStr);
   clipStr = clipStr.substring (clipStr.indexOf(" ") + 1);
   this.left = parseInt(clipStr);
}

function getEltClipLeft (elt) 
{ if (is.nav4up)     return (elt.clip.left);
  else if (is.ie4up) 
  {  var tempClip = new tempClipObj (elt);
     return tempClip.left;
  }
}

function getEltClipTop (elt) 
{ if (is.nav4up)     return (elt.clip.top);
  else if (is.ie4up) 
  {  var tempClip = new tempClipObj (elt);
     return tempClip.top;
  }
}

function getEltClipRight (elt) {
  if (is.nav4up)     return (elt.clip.right);
  else if (is.ie4up) 
  {  var tempClip = new tempClipObj (elt);
     return tempClip.right;
  }
}

function getEltClipBottom (elt) 
{ if (is.nav4up)     return (elt.clip.bottom);
  else if (is.ie4up) 
  {  var tempClip = new tempClipObj (elt);
     return tempClip.bottom;
  }
}

function getEltClipWidth (elt) 
{ if (is.nav4up)     return (elt.clip.width);
  else if (is.ie4up) return (getEltClipRight(elt) - getEltClipLeft(elt));
}

function getEltClipHeight (elt) 
{ if (is.nav4up)     return (elt.clip.height);
  else if (is.ie4up) return (getEltClipBottom(elt) - getEltClipTop(elt));
}

function getCurrentWinWidth() 
{ if (is.nav4up)     return(window.innerWidth);
  else if (is.ie4up) return(document.body.clientWidth);
}

function getCurrentWinHeight() 
{ if (is.nav4up)     return(window.innerHeight);
  else if (is.ie4up) return(document.body.clientHeight);
}

function getEltZIndex (elt) 
{ if (is.nav4up) return(elt.zIndex);
  else if (is.ie4up) return (elt.style.zIndex);
}

function setEltZIndex (elt, z) 
{ if (is.nav4up) elt.zIndex = z;
  else if (is.ie4up) elt.style.zIndex = z;
}

/* end CBDHTML derivative functions  */

function setEltBackgroundImage (elt, imageFilePath) 
{ if (is.nav4up) elt.background.src = imageFilePath;
  else if (is.ie4up) elt.style.backgroundImage = "url(" + imageFilePath + ")";
}

function getEltBackgroundImage (elt) 
{ if (is.nav4up) return (elt.background.src);
  else if (is.ie4up) { 
     var theURL = elt.style.backgroundImage;
     if (typeof(theURL) == "string")
     {  var URLlen = theURL.length;
        return (theURL.substring (4, URLlen-1));
     }
     else return(theURL);
  }
}

function setEltBackgroundColor (elt, colorNumber) 
{ if (is.nav4up) elt.bgColor = colorNumber;
  else if (is.ie4up) elt.style.backgroundColor = colorNumber;
}

var colorNameString = "aqua,black,blue,fuchsia,gray,green,lime,maroon,navy,olive,purple,red,silver,teal,yellow,white";
var colorNames   = new Array ("aqua", "black", "blue", "fuchsia", "gray",   "green", "lime", "maroon", "navy", "olive",  "purple", "red",    "silver", "teal", "yellow", "white");
var colorNumbers = new Array (0xffff, 0,       0xff,   0xff00ff,  0x808080, 0x8000,  0xff00, 0x800000, 0x80,   0x808000, 0x800080, 0xff0000, 0xc0c0c0, 0x8080, 0xffff00, 0xffffff);

function isColorName (aString)
{ return ( (typeof(aString) == "string") && (colorNameString.indexOf(aString) != -1));
}

function colorNameToNumber (colorName)
{ for (var i=0; i<16; i++) if (colorNames[i]==colorName) return colorNumbers[i];
  // Return string name unchanged if not found.
  // This handles IE4 non-CSS1-standard color names gracefully.
  return colorName;
}

function colorNumberToName (colorNumber)
{ for (var i=0; i<16; i++) if (colorNumbers[i]==colorNumber) return colorNames[i];
  return null;
}

function getEltBackgroundColor (elt) 
{ if (is.nav4up) return (elt.bgColor);
  else if (is.ie4up) {
     var colorVal = elt.style.backgroundColor;
     if (isColorName(colorVal)) return colorNameToNumber (colorVal);
     else if (typeof(colorVal) == "string") 
          return (("0x" + colorVal.substring(1)) - 0);
     else return colorVal;
  }
}

/* kshoop@real.com additions to the Elt API 
*/

function setEltDisplay(elt, value)
{
	if(value == "none")
	{
		setEltVisibility(elt, "hidden");
	}
	else
	{
		setEltVisibility(elt, "visible");
	}
	eltArrange(elt);
}

function getEltDisplay(elt)
{
	if (getEltVisibility(elt) == "visible")
	{
		return "block";
	}
	else
	{
		return "none";
	}
}

function getEltIndex(elt)
{
	ind = null;

	if (is.nav4up)
	{
		for (i=0; i < elt.parentLayer.document.layers.length; i++) 
		{
			whichHead = elt.parentLayer.document.layers[i];
			if (whichHead == elt) 
			{
				ind = i;
				break;
			}
		}
	}
	else if (is.ie4up)
	{
		for (i=0; i < document.all.length; i++) 
		{
			whichHead = document.all[i];
			if (whichHead == elt) 
			{
				ind = i;
				break;
			}
		}
	}

	return ind;
}

function getEltFromIndex(sourceDocument, ind)
{
	if (is.nav4up)
	{
		return sourceDocument.layers[ind];
	}
	else if (is.ie4up)
	{
		return sourceDocument.all[ind];
	}
}

function eltArrange(elt) 
{
	// THIS IS NOT WORKING!!!!!
	return;

	if (is.nav4up)
	{
		ThisDoc = elt.parentLayer.document;
		Thislength = ThisDoc.layers.length;

		nextY = 0;
		pageX = 0;

		for (i = 0; i < Thislength; i++) 
		{
			whichHead = getEltFromIndex(ThisDoc, i);
			if (typeof(whichHead) == "object")
			{
				//alert("Got Obj! " + whichHead.id);
				whichHeight = getEltHeight(whichHead);
				if (typeof(whichHeight) == "object")
				{
					//alert("Got Height! " + whichHeight);
					if (getEltVisibility(whichHead) != "hidden")
					{
						//alert("Move " + whichHead.id + " To " + nextY);
						moveEltTo(whichHead, pageX, nextY);
						//moveEltTo(whichHead, 0, 0);
						nextY += whichHeight;
					}
				}
			}
		}
	}
}

function getEltEx(eltname) 
{ 
	function _getNavEx( currentDocument )
	{
		// look for a layer
		var currentLayer = currentDocument.layers[eltname];

		if ( typeof( currentLayer ) == "object")
		{

			return currentLayer;
		}

		// look for a form/formfield

		for (var x=0; x<currentDocument.forms.length; x++)
		{

			if (currentDocument.forms[x].name == eltname)
			{
//				alert(eltname + " = a form");
				return currentDocument.forms[ x ] ;
			}

			// look for a form field

			var currentElement = eval( "currentDocument.forms[" + x + "]['" + eltname + "']" );
			if ( currentElement && typeof(currentElement) == "object" )
			{
//				alert(eltname + " = a form Element");
				return currentElement;
			}
		}

		// recurse down through the layers
//		alert(currentDocument.layers.length);
		for ( x=0; x<currentDocument.layers.length; x++)
		{
//			alert(currentDocument.layers[x].id);
			currentLayer = _getNavEx( currentDocument.layers[x].document );
			if (currentLayer && typeof(currentLayer) == "object")
			{
				return currentLayer;
			}
		}

		return currentLayer;
	}

	if (is.nav4up) 
	{

		return _getNavEx( document );
	}   
	else if (is.ie4up) 
	{
		var elt = eval('document.all.' + eltname);
		return(elt);  
	}
}

function getEltForm( formname )
{
	function _getNavEx( currentDocument )
	{
		var currentForm = null;

		for (var x=0; x<currentDocument.forms.length; x++)
		{
			if (currentDocument.forms[x].name == formname)
				return currentDocument.forms[x];
		}

		for ( x=0; x<currentDocument.layers.length; x++)
		{
			currentForm = _getNavEx( currentDocument.layers[x].document );
			if ( currentForm )
				return currentForm;
		}
		return currentForm;
	}

	if (is.nav4up) 
	{
		return _getNavEx( document );
	}
	else if (is.ie4up) 
	{

		var elt = eval('document.all.' + formname);
		return(elt);  
	}
}

function replaceEltContents(elt, newContents)
{
	if (is.nav4up) 
	{
		elt.document.write(newContents);
		elt.document.close();
	}
	else if (is.ie4up) 
	{
		elt.innerHTML = newContents;
	}
}

function setEltX (elt, x) {
  if (is.nav4up)     elt.pageX=x;
  else if (is.ie4up) elt.style.pixelLeft=x;
}

function getEltX (elt) 
{
	var Xparent = 0;
	function _getX(elt)
	{
		if (elt != null && typeof(elt) == 'object' && typeof(elt.offsetLeft) == 'number')
		{
			Xparent += elt.offsetLeft;
			_getX(elt.offsetParent);
		}
	}
	if (is.nav4up)     return (elt.pageX);
	else if (is.ie4up) 
	{
		_getX(elt);
		return (Xparent);
	}
}

function setEltY (elt, y) 
{ if (is.nav4up)     elt.pageY=y;
  else if (is.ie4up) elt.style.pixelTop=y;
}

function getEltY (elt) 
{
	var Yparent = 0;
	function _getIEY(elt)
	{
		if (elt != null && typeof(elt) == 'object' && typeof(elt.offsetTop) == 'number')
		{
			Yparent += elt.offsetTop;
			_getIEY(elt.offsetParent);
		}
	}

	if (is.nav4up)
	{
		return (elt.pageY);
	}
	else if (is.ie4up) 
	{
		_getIEY(elt);
	}

	return (Yparent);
}

function getEltWidthEx (elt)
{ if (is.nav4up) return(elt.clip.width);
  else if (is.ie4up) return(elt.offsetWidth);
}

function getEltHeightEx (elt)
{ if (is.nav4up) return(elt.clip.height);
  else if (is.ie4up) return(elt.offsetHeight);
}

